home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1191 / 1191.xpi / chrome / reminderfox.jar / content / reminderfox / alerts / reminderalert.js next >
Text File  |  2009-11-25  |  8KB  |  229 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 1998
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Scott MacGregor <mscott@netscape.com>
  23.  *   Jens Bannmann <jens.b@web.de>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var gFinalHeight = 50;  
  40. var gSlideIncrement = 1;
  41. var gSlideTime = 10;
  42. var gOpenTime = 5000; // total time the alert should stay up once we are done animating.
  43.                       // 10/22/09: was 3 seconds, bumping it up a bit due to user requests;
  44.                       // also, made a configurable option
  45. var gAlertListener = null;
  46. var gAlertTextClickable = false;
  47. var gAlertCookie = "";
  48.  
  49. function prefillAlertInfo() {
  50.         var todaysReminders = window.arguments[0].todaysreminders;
  51.         var upcomingReminders = window.arguments[0].upcomingreminders;
  52.         var alertType = window.arguments[0].alertTypeToShow;
  53.         var lblparent = document.getElementById("todaysRemindersBox2");    
  54.     
  55.         var tooltipChildrenReminders, todayDescription, todayBox, spacer;
  56.         // if no todays reminders, clear the description and today box
  57.         if ( todaysReminders == null ) {
  58.             //    remove old reminders box
  59.             tooltipChildrenReminders = document.getElementById("tooltipChildrenReminders2");
  60.             todayDescription = document.getElementById( "todayRemindersDescription2" );
  61.             if ( todayDescription != null ) {
  62.                 tooltipChildrenReminders.removeChild( todayDescription );
  63.             }
  64.             
  65.             todayBox = document.getElementById( "todaysRemindersBox2" );
  66.             if ( todayBox != null ) {
  67.                 tooltipChildrenReminders.removeChild( todayBox );        
  68.             }
  69.             
  70.             spacer = document.getElementById( "reminderSpacer2" );
  71.             if ( spacer != null ) {
  72.                 tooltipChildrenReminders.removeChild( spacer );        
  73.             }    
  74.         }
  75.         else {
  76.             // get the nodes from the tooltip
  77.             var todaysReminderClone =         window.arguments[0].todaysreminders.cloneNode( true );
  78.             for ( var i = 0; i < todaysReminderClone.childNodes.length; i++ ) {         
  79.                 var node = document.importNode( todaysReminderClone.childNodes[i], true);
  80.                 var cloneNode = node.cloneNode( true );
  81.                 lblparent.appendChild(cloneNode);         
  82.             }        
  83.         }
  84.     
  85.         // if no upcoming reminders, clear the description and upcoming box
  86.         if ( upcomingReminders == null ) {
  87.             tooltipChildrenReminders = document.getElementById("tooltipChildrenReminders2");    
  88.              spacer = document.getElementById( "reminderSpacer2" );
  89.             if ( spacer != null ) {
  90.                 tooltipChildrenReminders.removeChild( spacer );        
  91.             }    
  92.             
  93.             upcomingDescription = document.getElementById( "upcomingRemindersDescription2" );
  94.             if ( upcomingDescription != null ) {
  95.                 tooltipChildrenReminders.removeChild( upcomingDescription );
  96.             }
  97.             
  98.             upcomingBox = document.getElementById( "upcomingRemindersBox2" );
  99.             if ( upcomingBox != null ) {
  100.                 tooltipChildrenReminders.removeChild( upcomingBox );        
  101.             }                
  102.         }
  103.         else {
  104.             // get the nodes from the tooltip
  105.             var lblparent2 = document.getElementById("upcomingRemindersBox2");    
  106.             var upcomingReminderClone =         window.arguments[0].upcomingreminders.cloneNode( true );
  107.             
  108.             for ( var i = 0; i < upcomingReminderClone.childNodes.length; i++ ) {         
  109.                 var node = document.importNode( upcomingReminderClone.childNodes[i], true);
  110.                 lblparent2.appendChild(node.cloneNode(true));                        
  111.             }            
  112.         }
  113. }
  114.  
  115. function onAlertLoad()
  116. {
  117.  
  118.   // read out our initial settings from prefs.
  119.   try 
  120.   {
  121.     var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
  122.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  123.     var prefBranch = prefService.getBranch(null);
  124.     gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
  125.     gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
  126.    // gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
  127.     
  128.   try {
  129.         // get gOpenTime (it is specified in seconds - so multiply by 1000)
  130.         gOpenTime = reminderFox_prefs.getIntPref(REMINDER_FOX_PREF + "." + REMINDER_FOX_PREF_ALERTSLIDER_OPEN_TIME) * 1000;
  131.     } catch(e) {        
  132.         gOpenTime = 5000;  
  133.     }    
  134.   } catch (ex) {}
  135.  
  136.   sizeToContent();
  137.  
  138.   gFinalHeight = window.outerHeight;  //134  5 lines - 152 6 lines
  139.   
  140.   var alertSliderMaxHeight;
  141.   try {
  142.         alertSliderMaxHeight = reminderFox_prefs.getIntPref(REMINDER_FOX_PREF + "." + REMINDER_FOX_PREF_ALERTSLIDER_MAX_HEIGHT);
  143.     } catch(e) {        
  144.         alertSliderMaxHeight = 134;  // default to 134
  145.     }    
  146.       if ( alertSliderMaxHeight <= 0 ) {
  147.           alertSliderMaxHeight = 134;
  148.       }
  149.   
  150.   if ( gFinalHeight > alertSliderMaxHeight ) {
  151.       gFinalHeight = alertSliderMaxHeight;
  152.   }
  153.  
  154.   window.outerHeight = 1;
  155.  
  156.   // be sure to offset the alert by 10 pixels from the far right edge of the screen
  157.   window.moveTo( (screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availTop + screen.availHeight - window.outerHeight);
  158.  
  159.   setTimeout(animateAlert, gSlideTime);
  160.   
  161.  
  162.   
  163. }
  164.  
  165. function playAlertSound() {
  166.     // play a sound for notification (if the user elects to)
  167.     try {
  168.         var playSound = true;
  169.         try {
  170.             playSound = reminderFox_prefs.getBoolPref(REMINDER_FOX_PREF + "." +  REMINDER_FOX_ALERT_SOUND);
  171.         }
  172.         catch ( e) {
  173.         }
  174.         if ( playSound ) {
  175.             reminderFox_playSound();
  176.           } 
  177.     }
  178.     catch ( e ) {
  179.     }
  180. }
  181.  
  182. function onAlertClick() {
  183.     if ( gOpenTime <= 0 &&  window.outerHeight >= gFinalHeight) {  // only close alert after it's opened
  184.         gOpenTime = 1; // so next click will open dialog
  185.         closeAlert();
  186.         //window.close();  // this will close immediately, instead of slide-close
  187.     }
  188.     else {
  189.         reminderFox_openAddRemindersDialog();
  190.     }
  191. }
  192.  
  193.  
  194. function animateAlert()
  195. {
  196.  
  197.   if ( window.outerHeight == 1 ) {
  198.         playAlertSound();
  199.   }
  200.   if (window.outerHeight < gFinalHeight)
  201.   {
  202.     window.screenY -= gSlideIncrement;
  203.     window.outerHeight += gSlideIncrement;
  204.     setTimeout(animateAlert, gSlideTime);
  205.   }
  206.   else
  207.     if ( gOpenTime > 0 ) { 
  208.         setTimeout(closeAlert, gOpenTime);  
  209.     }
  210.     else { 
  211.         // we will wait until alert is clicked
  212.     }
  213. }
  214.  
  215. function closeAlert()
  216. {
  217.   if (window.outerHeight > 1)
  218.   {
  219.     window.screenY += gSlideIncrement;
  220.     window.outerHeight -= gSlideIncrement;
  221.     setTimeout(closeAlert, gSlideTime);
  222.   }
  223.   else
  224.   {
  225.     if (gAlertListener)
  226.       gAlertListener.observe(null, "alertfinished", gAlertCookie); 
  227.     window.close(); 
  228.   }
  229. }